﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AussieAuto.DataAccess;
using AussieAuto.BusinessLogic;

namespace AussieAuto.BusinessLogic
{
    public class CarOwnershipLogic : BusinessLogicBaseClass
    {

 

      public  bool saveCarOwnership(CustomerOwnsCar customerOwnsCar)
        {
            bool result = false;
            try
            {
                

                .AddToCustomerOwnsCars(customerOwnsCar);
                result = true;
                entityContext.SaveChanges();
            }
            catch (Exception ex)
            {
                //TO DO: INSERT LOGGING 
                throw ex;
            }
            return result;
        }


      public  List<Car> getCarsByCustomer(Customer  cutomer)
        {
            List<Car> carList = new List<Car>();  
            try
            {
                var carLinqList = from Car c in entityContext.Cars
                                join co in entityContext.CustomerOwnsCars on c.CarId equals co.CarId
                                join cust in entityContext.Customers on co.CustomerId equals cust.CustomerId
                                 
                             select c;

                carList.AddRange(carLinqList.ToList<Car>());
              
            }
            catch (Exception ex)
            {
                //INSERT LOGGING

            }
            return carList;
        }

    }
}
